#!/bin/bash

#!/bin/bash

############################################
##
##    ATVFiles Install Script
##
##    Created by: h3lbr0 // atvMod.com
##
############################################

# source /Users/frontrow/atvMod_com/scripts/common.vars
PACKAGE="nitotv"
PACKAGE_URL="http://nitosoft.com/nitoTVInstaller_tt.zip"
PACKAGE_FILE="nitoTVInstaller_tt.zip"
 
# echo "Downloading Installer..." > $TMP_LOG; $LOGGER $PACKAGE
# wget -q $PACKAGE_URL 2> $TMP_LOG; $LOGGER $PACKAGE
# echo "Done." > $TMP_LOG; $LOGGER $PACKAGE
# 
# echo "Unpacking Installer..." > $TMP_LOG; $LOGGER $PACKAGE
# unzip $PACKAGE_FILE 2> $TMP_LOG; $LOGGER $PACKAGE
# echo "Done." > $TMP_LOG; $LOGGER $PACKAGE
# 
# echo "Running Installer..." > $TMP_LOG; $LOGGER $PACKAGE
# sudo rm -rf /Library/Receipts/nitoTV.pkg/ 2> $TMP_LOG; $LOGGER $PACKAGE
# sudo installer -pkg nitoTV\ Take\ Two/nitoTV.pkg -target / 2> $TMP_LOG; $LOGGER $PACKAGE
# echo "Done." > $TMP_LOG; $LOGGER $PACKAGE
# 
# echo "Fixing OpenAL.framework..." > $TMP_LOG; $LOGGER $PACKAGE
# sudo cp /System/Library/CoreServices/Finder.app/Contents/PlugIns/nitoTV.frappliance/Contents/Resources/OpenAL.tar.gz ./ 2> $TMP_LOG; $LOGGER $PACKAGE
# sudo tar xvzf OpenAL.tar.gz
# sudo cp -R OpenAL.framework /System/Library/Frameworks/ 2> $TMP_LOG; $LOGGER $PACKAGE
# sudo chown -R 0:0 /System/Library/Frameworks/OpenAL.framework 2> $TMP_LOG; $LOGGER $PACKAGE 
# sudo chmod -R 755 /System/Library/Frameworks/OpenAL.framework 2> $TMP_LOG; $LOGGER $PACKAGE 
# echo "Done." > $TMP_LOG; $LOGGER $PACKAGE
# 
# unset PACKAGE


#Download and run the installer
mkdir /Users/frontrow/atvMod/packages/$PACKAGE
cd  /Users/frontrow/atvMod/packages/$PACKAGE
wget -q $PACKAGE_URL
unzip $PACKAGE_FILE
sudo rm -rf /Library/Receipts/nitoTV.pkg/
sudo installer -pkg nitoTV\ Take\ Two/nitoTV.pkg -target /


# Fixing OpenAL.framework
sudo cp /System/Library/CoreServices/Finder.app/Contents/PlugIns/nitoTV.frappliance/Contents/Resources/OpenAL.tar.gz ./
sudo tar xvzf OpenAL.tar.gz
sudo cp -R OpenAL.framework /System/Library/Frameworks/
sudo chown -R 0:0 /System/Library/Frameworks/OpenAL.framework
sudo chmod -R 755 /System/Library/Frameworks/OpenAL.framework